<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情页</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_detail.css">
    <!-- 引入依赖 -->
    <link rel="stylesheet" href="editor.md/css/editormd.min.css">
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="js/a.js"></script>
</head>

<body>
    <div class="nav">
        <img src="img/head.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- spacer只是占位 -->
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.htm">写博客</a>
        <a href="logout">注销</a>

    </div>

    <!-- 这个div表示页面的主区域 -->
    <div class="container">
        <!-- 左侧内容区 -->
        <div class="container-left">
            <div class="card">
                <!-- 用户的头像 -->
                <img src="img/dog2.jpg" alt="">
                <!-- 用户的名字 -->
                <h3>我的博客</h3>
                <a href="#">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>--</span>
                    <span>--</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容区 -->
        <div class="container-right">
            <div class="blog_detail">
                <h3></h3>
                <div class="date"></div>
                <div id="content" style="background-color: transparent;"></div>
            </div>
        </div>
    </div>

    <script>

        //获取当前博客详细内容
        function getBlog() {
            $.ajax({
                type: "get",
                url: "blog" + location.search,
                success: function (body) {

                    //构建博客详情标签

                    let h3 = document.querySelector(".blog_detail>h3");
                    h3.innerHTML = body.title;

                    let dateDiv = document.querySelector(".blog_detail>.date");
                    dateDiv.innerHTML = body.postTime;

                    // let contentDiv = document.querySelector(".blog_detail>.content");
                    // contentDiv.innerHTML = body.content;

                    // 此处使用 editor.md 来进行渲染
                    editormd.markdownToHTML('content', { markdown: body.content });

                }
            });
        }
        let data = null;
        //获取当前博客作者详细信息
        function getUserInfo() {
            $.ajax({
                type: 'get',
                url: 'userInfo' + location.search,
                success: function (body) {
                    data = body;
                    let h3 = document.querySelector('.container-left>.card>h3');
                    h3.innerHTML = body.username;

                    let a = document.querySelector(".container-left>.card>a");
                    a.href = body.github;


                }
            })
        }

        function deleteBlog() {
            $.ajax({
                type:'post',
                url:'delete' + location.search,
                data:"",
                success:function(body) {
                    let navDiv = document.querySelector('.nav');
                    let flg = body.flg;
                    console.log(flg);
                    if(flg == "true") {
                        console.log(flg);
                        let a = document.createElement("a");
                        a.href = "delete" + location.search;
                        a.innerHTML = "删除";
                        navDiv.appendChild(a);
                    } else {
                        console.log(flg);
                    }

                }
            });
        }

        // //获取当前作者博客数量
        // function getBlogNumber() {
        //     $.ajax({
        //         type: 'post',
        //         url:'userInfo',
        //         data :JSON.stringify(data),
        //         contentType: 'application/json; charset=utf8',
                
        //     })
        // }
        
        getBlog();
        getLoginStatus();
        getUserInfo();
        deleteBlog()
    </script>
</body>

</html>